<?php
@header("Content-Type:text/json;charset=utf-8");
@header("Access-Control-Allow-Origin:*");
$conn = mysqli_connect("b-sjisyki6cozhtk.bch.rds.gz.baidubce.com:3306", "b_sjisyki6cozhtk", "12345678", "b_sjisyki6cozhtk");

if (!$conn) { // 如果连接失败 => 脚本在当前退出
    exit('{"status":false,"message":"数据库链接失败"}');
}
mysqli_query($conn, "set names utf8");
mysqli_query($conn, "set character set utf-8"); // 向数据库存数据

if (!isset($_GET["id"])) {
    exit('{"status":false,"message":"请传入完整参数"}');
}

$id = $_GET["id"];
$obj = array();

$sql = "select * from `idbiao` where id in ($id)";
$result = mysqli_query($conn, $sql);
$obj = array();
if ($result) { // 有结果对象 => 可能有数据
    $item = mysqli_fetch_assoc($result);
    // print_r($item === null);
    if ($item) { // $item == true  =>存在该学员成绩 => 删除
        $sql = "delete from `idbiao` where id in ($id)";
        $result = mysqli_query($conn, $sql);
        // echo $result;
        if ($result) { // true => 语句执行成功
            $rows = mysqli_affected_rows($conn);

            if ($rows > 0) {
                $obj["status"] = true;
                $obj["message"] = "删除成功";
            } else {
                $obj["status"] = false;
                $obj["message"] = "删除失败";
            }
        } else {
            $obj["status"] = false;
            $obj["message"] = "sql语句有误";
            $obj["sql"] = $sql;
        }
    } else { // 没有的话不能删除
        $obj["status"] = false;
        $obj["message"] = "不存在该商品!";
    }
} else {
    $obj["status"] = false;
    $obj["message"] = "sql语句有误";
    $obj["sql"] = $sql;
}
echo json_encode($obj);
